<?php

namespace App\Providers;

use App\Services\CodeService;
use App\Services\FileService;
use App\Services\RoleService;
use App\Utils\Auth;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        $this->app->singleton("Code", CodeService::class);
        $this->app->singleton("File", FileService::class);
        $this->app->singleton("Role", RoleService::class);
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        //注册标签
        Blade::if('b', function ($action) {
            $actions = explode('@', $action);
            if (count($actions) == 2) {
                return Auth::can($actions[0], $actions[1]);
            }
            return Auth::can($action);
        });
        view()->composer(['backend.layouts.app'], function ($view) {
            $breadcrumb = \App\Utils\Auth::getMenusMap();
            $view->with('breadcrumb',$breadcrumb);
        });
    }
}
